#pragma once

#include <vector>

namespace solution_073
{

class Solution
{
public:
    void setZeroes(std::vector< std::vector<int> >& matrix)
    {
        bool set_row0 = false;
        bool set_col0 = false;

        for (int col = 0; col < (int)matrix.front().size(); ++col) {
            if (matrix[0][col] == 0)
                set_row0 = true;
        }
        for (int row = 0; row < (int)matrix.size(); ++row) {
            if (matrix[row][0] == 0)
                set_col0 = true;
        }

        for (int row = 1; row < (int)matrix.size(); ++row) {
            for (int col = 1; col < (int)matrix.front().size(); ++col) {
                if (matrix[row][col] == 0) {
                    matrix[row][0] = 0;
                    matrix[0][col] = 0;
                }
            }
        }

        for (int row = 1; row < (int)matrix.size(); ++row) {
            for (int col = 1; col < (int)matrix.front().size(); ++col) {
                if (matrix[0][col] == 0 || matrix[row][0] == 0)
                    matrix[row][col] = 0;
            }
        }

        if (set_row0)
            std::fill(matrix[0].begin(), matrix[0].end(), 0);
        if (set_col0) {
            for (int row = 0; row < (int)matrix.size(); ++row)
                matrix[row][0] = 0;
        }
    }
};

}  /* namespace solution_073 */
